Added Pyramid of Stars Python Script#3256
Open
Saurabh6266 wants to merge 2 commits intoavinashkranjan:mainfrom
Open
Added Pyramid of Stars Python Script#3256Saurabh6266 wants to merge 2 commits intoavinashkranjan:mainfrom
Saurabh6266 wants to merge 2 commits intoavinashkranjan:mainfrom
Conversation
Program to create a pyramid of stars.
Reviewer's GuideAdds a new pyramid_of_stars.py script that interactively builds and prints a centered star pyramid using modular functions for input validation and pattern generation. Class diagram for pyramid_of_stars.py functionsclassDiagram
class get_positive_int {
+int get_positive_int(prompt: str)
"Prompt user for positive integer input"
}
class draw_pyramid {
+void draw_pyramid(rows: int)
"Print centered pyramid of stars"
}
class main {
+void main()
"Entry point: gets input and draws pyramid"
}
main --> get_positive_int
main --> draw_pyramid
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- Consider simplifying the star generation by using '' * (2 * i - 1) for each row instead of ' ' * i and rstrip to avoid trailing spaces more directly.
- For greater flexibility and ease of automation, consider adding an optional command-line argument (via argparse) for the number of rows instead of relying solely on interactive input.
- The diff shows an unintended duplicate entry (“Pyramid of stars”) after the main script – please remove or correct it so only the intended .py file is added.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider simplifying the star generation by using '*' * (2 * i - 1) for each row instead of '* ' * i and rstrip to avoid trailing spaces more directly.
- For greater flexibility and ease of automation, consider adding an optional command-line argument (via argparse) for the number of rows instead of relying solely on interactive input.
- The diff shows an unintended duplicate entry (“Pyramid of stars”) after the main script – please remove or correct it so only the intended .py file is added.
## Individual Comments
### Comment 1
<location> `pyramid_of_stars.py:5-13` </location>
<code_context>
+
+def get_positive_int(prompt: str) -> int:
+ """Prompt the user until they provide a positive integer (> 0)."""
+ while True:
+ try:
+ value = int(input(prompt).strip())
+ if value <= 0:
+ print("Please enter a positive integer greater than zero.")
+ continue
+ return value
+ except ValueError:
+ print("Invalid input. Please enter a valid integer.")
+
+
</code_context>
<issue_to_address>
**suggestion:** Consider handling KeyboardInterrupt to allow graceful exit.
Currently, pressing Ctrl+C results in an unhandled exception. Catching KeyboardInterrupt would allow the program to exit cleanly.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+5
to
+13
| while True: | ||
| try: | ||
| value = int(input(prompt).strip()) | ||
| if value <= 0: | ||
| print("Please enter a positive integer greater than zero.") | ||
| continue | ||
| return value | ||
| except ValueError: | ||
| print("Invalid input. Please enter a valid integer.") |
There was a problem hiding this comment.
suggestion: Consider handling KeyboardInterrupt to allow graceful exit.
Currently, pressing Ctrl+C results in an unhandled exception. Catching KeyboardInterrupt would allow the program to exit cleanly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new Python script named pyramid_of_stars.py that prints a beautiful pyramid pattern made of stars (*) based on user input.
The script is simple, interactive, and designed to demonstrate the fundamentals of loops, string formatting, and user input handling in Python.
It is a perfect beginner-friendly contribution for learning pattern generation and console output formatting.
🚀 Features
💻 Code Overview
The core logic uses:
🧠 Concepts Demonstrated
🧾 Example Output
Enter number of rows: 5
*
Thank you so much!
Summary by Sourcery
Introduce a new Python script to interactively generate a centered pyramid of stars based on user-specified rows
New Features: